package com.hardroid.workload.ui.widget;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hardroid.workload.R;
import com.hardroid.workload.utils.HardroidUtils;
import com.hardroid.workload.utils.UIUtils;
import com.hardroid.workload.workcalc.ObsvDay;
import com.hardroid.workload.workcalc.ObsvResultItem;

public class ResultQuestItemView extends LinearLayout{

	public ObsvDay day;
	public int id;
	
	private TextView dayText;
	private TextView dateText;
	private TextView kelonggaranText;
	private TextView p1Text;
	private TextView p2Text;
	private TextView p1p2Text;
	
	public ResultQuestItemView(Context context , ObsvDay day, int id) {
		super(context);
		// TODO Auto-generated constructor stub
		
		
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		inflater.inflate(R.layout.list_item_result_quest, this, true);
		
		dateText = (TextView) findViewById(R.id.list_item_result_date);
		dayText = (TextView) findViewById(R.id.list_item_result_day);
		kelonggaranText = (TextView) findViewById(R.id.list_item_result_kelonggaran);
		p1Text = (TextView) findViewById(R.id.list_item_result_p1);
		p2Text = (TextView) findViewById(R.id.list_item_result_p2);
		p1p2Text = (TextView) findViewById(R.id.list_item_result_p1p2);
		
		setResult(day, id);
	}
	
	public ResultQuestItemView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public void setResult(ObsvDay day, int id){
		this.day = day;
		this.id = id;
		updateView();
						
	}
	
	public void updateView(){		
		if (UIUtils.isHoneycombTablet(getContext())){
//			System.out.println(day.employer.name + "--- begin" + (id+1));
			dayText.setText((id+1)+"");
			dateText.setText(HardroidUtils.dateToSDate(day.obsvDate));
			kelonggaranText.setText(""+day.questionaire.getNilaiKelonggaran(day.employer.male)+"");
			int p1 = day.questionaire.getP1();
//			System.out.println("P1 "+p1);
			float p2 = day.questionaire.getP2();
//			System.out.println("P2 "+p2);			
			float p1p2 = p1*p2;
//			System.out.println("P1 P2 "+p1p2);
//			System.out.println(day.employer.name + "--- end" + (id+1));
			p1Text.setText(p1+"");
			p2Text.setText(p2+"");
			p1p2Text.setText(p1p2+"");		
		}		
	}

}
